package servlet;

import entity.StudentInfo;
import service.StudentInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/StudentUpdateServlet")
public class StudentUpdateServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("test/html;charset=utf-8");

        StudentInfo studentInfo = new StudentInfo(Integer.parseInt(req.getParameter("sid")),
                        req.getParameter("sname"),
                        req.getParameter("sgender"),
                        Integer.parseInt(req.getParameter("sage")),
                        req.getParameter("saddress"),
                        req.getParameter("semail"));


        req.getSession().setAttribute("update",new StudentInfoService().update(studentInfo));
        resp.sendRedirect("StudentListServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
